<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <link class="theme" rel="stylesheet" type="text/css" href="./css/color/blue.css" />
    <script type="text/javascript" src="./script/doT.min.js"></script>

</head>

<body>
    <header class="aui-bar aui-bar-nav header">
        <!-- <a class="aui-pull-left">
        <span class="aui-iconfont aui-icon-left"></span>
    </a> -->
        <div class="aui-title"><span>市管领导干部信息查询系统--条件查询</span></div>
        <a class="aui-pull-right aui-btn">
            <span class="fa fa-user-circle-o" onclick="user()"></span>
        </a>
    </header>
    <div class="header-d"></div>
    <!-- <div class="list-t">
        <img src="images/cover_logo.png">
        <span>中共佳木斯市委组织部</span>
    </div> -->
    <div id="list">
    </div>
    <script type='text/template' id='template'>

        <div class="classify">
            {{~it :value:index}}
            <ul class="classify-t">
                <li>
                  {{? value.mflag==1}}
                    <h3 onclick="click_in({{=value.ID}})">{{=value.PlanName}}</h3>
                    {{ } }}
                </li>
            </ul>
            {{~}}
        </div>
    </script>
</body>
<script type="text/javascript" src="./script/api.js"></script>

</html>
<script>

    function click_in(n) {
      var db = api.require('db');
      var sql ='SELECT * from (SELECT a.ID as userID,a.I01,a.I02,a.I03,a.I04,a.I06,a.I07,a.I08,a.I16,a.I45,a.I53,b.Ldr_id,c.ID,d.ID, d.PID as d from Base_Info as a join Base_DptLdr as b join Base_Depart as c join Base_Level as d WHERE b.Ldr_id =a.ID AND c.ID = b.Dpt_ID AND c.PID = d.ID) as b  inner join Base_level as a WHERE a.ID = b.d AND'

      db.selectSql({
          name: 'data',
          sql: 'SELECT * FROM Base_PlanDetail WHERE PID = ' + n,
      }, function(ret, err) {
          if (ret.status != false) {
            var newData = ret.data;
            for (var i = 0; i < newData.length; i++) {

                if (newData[i].ColType=='System.String') {
                  //取第一个
                  if (newData[i].E1 !='×') {
                    var sy;
                    //判断e1 符号
                    if (newData[i].E1=='等于') {
                      sy ='==';
                    }else if(newData[i].E1=='＜') {
                      sy='<';
                    }else if (newData[i].E1=='＞') {
                    sy='>';
                  }else {
                    sy=newData[i].E1;
                  }
                    var d =  colName(newData[i].ColName);
                    sql= sql+' '+d+sy+" '"+newData[i].V1+"' ";

                    if (i != newData.length-1) {
                      sql=sql+' AND '
                    }


                  }
                }else {
                    if (newData[i].E1 !='×') {
                        var sy;
                        if (newData[i].E1=='等于') {
                          sy ='==';
                        }else if(newData[i].E1=='＜') {
                          sy='<';
                        }else if (newData[i].E1=='＞') {
                        sy='>';
                      }else {
                        sy=newData[i].E1;
                      }
                      var d =  colName(newData[i].ColName);
                      sql= sql+' '+d+sy+" '"+newData[i].V1+"' AND" ;
                      if (newData[i].E2=='等于') {
                        sy ='==';
                      }else if(newData[i].E2=='＜') {
                        sy='<';
                      }else if (newData[i].E2=='＞') {
                      sy='>';
                    }else {
                      sy=newData[i].E2;
                    }
                      var d =  colName(newData[i].ColName);
                      sql= sql+' '+d+sy+ " '"+newData[i].V2 + "' ";
                      if (i != newData.length-1) {sql=sql+' AND '}
                    }else {
                      //E1 =='×'
                      var sy;
                      if (newData[i].E2=='等于') {
                        sy ='==';
                      }else if(newData[i].E2=='＜') {
                        sy='<';
                      }else if (newData[i].E2=='＞') {
                      sy='>';
                    }else {
                      sy=newData[i].E2;
                    }
                      var d =  colName(newData[i].ColName);
                      sql= sql+' '+d+sy+" '"+newData[i].V2 + "' ";
                      if (i != newData.length-1) {sql=sql+' AND '}
                    }

                }//newData[i].ColType=='System.DateTime' 结束

            }//for结束
          // console.log(sql);

        //   var h;
        //   if(window.orientation==180||window.orientation==0){
        //         // alert("竖屏状态！")
        //         h = api.winHeight - 50;
        //    }
        // if(window.orientation==90||window.orientation==-90){
        //         // alert("横屏状态！")
        //         h = api.winHeight;
        //     }

            api.openFrame({
                name: 'fananSearch',
                url: './fananSearch.html',
                rect: {
                    x: 0,
                    y: 0,
                    w: 'auto',
                    h: api.winHeight -50
                },
                pageParam: {
                    sql: sql,
                },
                bounces: false,
                bgColor: 'rgba(0,0,0,0)',
                vScrollBarEnabled: true,
                hScrollBarEnabled: true
            });
            api.showProgress({
                title: '努力加载中...',
                text: '先喝杯茶...',
                modal: false
            });

          } else {
              alert(JSON.stringify(err));
          }
      });

    }


    function colName(n) {

      if (n=='CSNY') {
        n=' I03 '
      }else if (n=='XB') {
        n=' I02 '
      }else if (n=='RDSJ') {
        n=' I07 '
      }else if (n=='MZ') {
        n=' I04 '
      }else if (n=='AGE') {
        n=' I53 '
      }
      return n;
    }



    apiready = function() {
      var color = $api.getStorage('color');
      $(".theme").attr("href", color);
        var sql = 'select * from Base_Plan'
        var db = api.require('db');
        db.selectSql({
            name: 'data',
            sql: sql
        }, function(ret, err) {

            if (ret.status != false) {
                api.hideProgress();
                title = ret.data;
                var dotFn = doT.template(template.innerHTML);
                var html = dotFn(ret.data);
                var list = $api.byId('list');
                $api.html(list, html);
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    function user() {
        api.openWin({
            name: 'user',
            url: './user.html',
        });
    }
</script>
